package com.atguigu.common.config.exception;

import com.atguigu.result.ResultCodeEnum;
import lombok.Data;

/**
 * ClassName GuiguException
 * Package: com.atguigu.common.config.exception
 * ProjectName guigu-oa-parent
 * Description:
 * 自定义全局异常类
 *
 * @Author: 比特张
 * @Create: 2023/4/18 - 16:05
 * @Version: v1.0
 */

@Data
public class GuiguException extends RuntimeException {
    private Integer code;//状态码
    private String msg;//描述信息

    /**
     * 通过状态码和错误消息创建异常对象
     *
     * @param code
     * @param msg
     */
    public GuiguException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    /**
     * 接收枚举类型对象
     *
     * @param resultCodeEnum
     */
    public GuiguException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMessage();
    }

    @Override
    public String toString() {
        return "GulpException{" +
                "code=" + code +
                ", msg=" + this.getMessage() +
                '}';
    }

}
